// var page = 1,limit=10;
// var totalPage = 0;
var club_totaldata=[];
var club_params={
    page:1,
    limit:10,
    totalPage : 0,
    recommend:null
};
window.addEventListener('onDropdown', function(event){
    //console.log('下接刷新：' );

    if(club_params.page<club_params.totalPage){
        club_params.page++;

        loaddata(club_params.page,club_params.limit,club_params.recommend);
    }else{
        // console.log(page)
        //  pop_up("没有更多了...")
    }
});
function setmenu(menuid) {
    if(menuid==1){
        $("#menu1").removeClass('club-menu-item-unselected');
        $("#menu1").addClass('club-menu-item-selected');
        $("#menu2").removeClass('club-menu-item-selected');
        $("#tipimage").css('left','0px');
        // club_params.recommend=0;
        club_totaldata=[];
        loaddata(1,10);

    }else{
        $("#menu2").removeClass('club-menu-item-unselected');
        $("#menu2").addClass('club-menu-item-selected');
        $("#menu1").removeClass('club-menu-item-selected');
        $("#tipimage").css('left','25%');
        club_params.recommend=1;
        club_totaldata=[];
        loaddata(1,10,1);
    }
};
function newclub(){
    server.loadindex('page/club/newclub/newclub');
};
//去动态详情
function todongtaidetail(dongtaiid) {
    server.loadindex('page/club/viewclub/viewclub','dtid='+dongtaiid);
}
function loaddata(page,limit,recommend){
    server.req('wechat/club/list',{page:club_params.page,limit:club_params.limit,recommend:recommend},function (res) {

        if(res.code==0){
            club_params.totalPage = res.totalPage;

            var d = res.data;
            var strImages;
            var vImages;
            var htmlImages="";
            d.forEach(function (club,clubindex) {
                //处理图片显示
                htmlImages="";
                strImages = club.images;
                vImages="";
                if(strImages){
                    if(strImages.indexOf(';')!=-1){
                        vImages = strImages.split(';');
                    }else{
                        vImages=strImages;
                    }
                }

                if(vImages){

                    if(vImages instanceof Array)
                    vImages.forEach(function(item,index){
                        htmlImages = htmlImages+"<img src='"+item+"' />";
                    })
                    else
                        htmlImages="<img src='"+vImages+"' />"
                    club.htmlImage = htmlImages;
                }else{
                    club.htmlImage ="";
                }

                //处理长内容的问题
                if(club.content.length>100){
                    club.content = club.content.substring(0,100)+'...';
                }
            })
            console.log(res);
            if(club_params.page!=1)
            club_totaldata=  club_totaldata.concat(res.data);
            else
                club_totaldata= res.data;
           console.log(club_totaldata)
            server.loadData('.content',{data:club_totaldata});
        }
    })
};
setmenu(1);
//loaddata(1,10,0);

